package hello;

import java.util.*;
import java.math.*;

import org.dom4j.*;
import org.dom4j.io.*;

import org.hibernate.*;
import persistence.*;
import auction.model.*;

public class HelloWorldOneToManyJoin
{
	
	
	public static void main(String[] args)throws Exception
	{
		
		Session s=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=s.beginTransaction();

		ItemOneToManyJoin item =new ItemOneToManyJoin();
		UserOneToManyJoin user=new UserOneToManyJoin();
		
		user.getBoughtItems().add(item);
		item.setBuyer(user);
		
		s.save(user);
		s.save(item);
		
		
		
		
		tx.commit();
		s.close();
		
		
		
		Session s1=HibernateUtil.getSessionFactory().openSession();
		Transaction tx1=s1.beginTransaction();
		
		
		ItemOneToManyJoin i=(ItemOneToManyJoin)s1.load(ItemOneToManyJoin.class,7L);
		UserOneToManyJoin u=(UserOneToManyJoin)s1.load(UserOneToManyJoin.class,3L);
		
		//u.getBoughtItems().add(i);
		//i.setBuyer(u);
		
		
		tx1.commit();
		s1.close();
		
		
		
		//HibernateUtil.stat();
		HibernateUtil.shutdown();
	}
	
	public static void getParent(Class clazz)
	{
		Class parent=clazz.getSuperclass();
	  if(parent !=null)
	  {
			System.out.println("###"+parent.getName());
			getParent(parent);
		}
	}
	
	static void out(Object obj)
	{
		System.out.println(obj);
	}
}
